package terra.network.packet.server;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;

public class LoginAnswer extends Packet {

	public static final byte LOGIN_FAIL = 1;
	public static final byte LOGIN_ACCEPT = 0;
	public static final byte LOGIN_NO_ACC = 2;
	public static final byte LOGIN_CURRENT_IS_ONLINE = 3;
	
	public byte answer;
	public int playerId;
	
	public LoginAnswer(byte answe,int pId) {
		answer = answe;
		playerId = pId;
	}

	public LoginAnswer() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer();
		buf.writeByte(getId());
		buf.writeInt(playerId);
		buf.writeByte(answer);
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		playerId = buf.readInt();
		answer = buf.readByte();
		return this;
	}

	@Override
	public int getLength() {
		return 6;
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getId() {
		return 5;
	}
	
	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}
}
